package com.longge;

public class DistributeCandiesIII {
    public int distributeCandies(int n, int limit) {

        int residue = 0, ans = 0;
        for (int i = 0; i <= limit; i++) {
            residue = n - i;
            if (residue>=0){
                for (int j = 0; j <= limit; j++) {
                    int temp = residue - j;
                    if (temp>=0&&temp <= limit) {
                        ans++;
                    }
                }
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        int i = new DistributeCandiesIII().distributeCandies(3, 3);
        System.out.println(i);
    }
}
